package com.youtellv1.service.Impl;

import com.youtellv1.entity.TeacherSign;
import com.youtellv1.entity.Teachers;
import com.youtellv1.mapper.TeacherSignMapper;
import com.youtellv1.service.TeacherSignService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

@Service
public class TeacherSignServiceImpl implements TeacherSignService {
    @Resource
    private TeacherSignMapper teacherSignMapper;

    @Override
    public boolean hasSignedOnDate(Integer tid, Date date) {
        int count = teacherSignMapper.countByTidAndDate(tid, date);
        return count > 0;
    }

    @Override
    public boolean hasSignedToday(Integer tid) {
        int count = teacherSignMapper.countTodaySign(tid);
        return count > 0;
    }

    @Override
    public void insertSignRecord(TeacherSign teacherSign) {
        teacherSignMapper.insertSignRecord(teacherSign);
    }


    @Override
    public void insertTodaySign(TeacherSign teacherSign) {
        teacherSignMapper.insertSignRecord(teacherSign);
    }

    @Override
    public List<Date> findAllSignDates(Integer tid) {
        return teacherSignMapper.findAllSignDates(tid);
    }

    @Override
    public List<Date> findThisMonthSignDates(Integer tid) {
        // 获取当前年月，格式 yyyy-MM
        String yearMonth = new SimpleDateFormat("yyyy-MM").format(new Date());
        return teacherSignMapper.findThisMonthSignDates(tid, yearMonth);
    }

    @Override
    public boolean isTodaySigned(Integer tid) {
        return hasSignedToday(tid);
    }

}
